import VueRouter from "vue-router"
const router = new VueRouter({
    routes: [
        //配置路由的路径
        {
            path: '/',
            name: 'Login',
            component: () => import('../components/Login.vue'),
        },
        {
            path: '/Chat',
            name: 'Chat',
            component: () => import('../components/Chat.vue'),
            children: [
                {
                    path: '/AddNewFriend',
                    name: 'AddNewFriend',
                    component: () => import('../components/AddNewFriend.vue')
                },
                {
                    path: '/ReceiveNewFriend',
                    name: 'ReceiveNewFriend',
                    component: () => import('../components/ReceiveNewFriend.vue')
                }
            ]
        },
        {
            path: '/Login',
            name: 'Login',
            component: () => import('../components/Login.vue')
        }
    ]
})
//添加以下代码
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
// 全局的前置守卫
router.beforeEach((to, from, next) => {
    console.log('前置路由守卫beforeEach')
    console.log(to)
    console.log(from)
    next()
})
// 后置路由守卫
// router.afterEach((to, from, next) => {
//     console.log('后置路由守卫affterEach')
//     next()
// })
// 全局的解析守卫
router.beforeResolve((to, from, next) => {
    console.log('全局解析守卫beforeResolve')
    next()
})
export default router;